package com.lpc.android.abc.base.base;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.lpc.android.abc.base.utils.ActivityStackManager;
import com.lpc.android.abc.base.widget.MProgressDialog;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * Created by lpc on 2016/10/30.
 */

public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity {

//    protected View mContentView;
    protected MProgressDialog mProgressDialog;

    protected P mPresenter;
    protected Unbinder mUnbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityStackManager.getInstance().push(this);
        setContentView(setActivityLayoutId());
        mUnbinder = ButterKnife.bind(this);
        initData();
    }

    protected abstract int setActivityLayoutId();

    /*@Override
    public void setContentView(@LayoutRes int layoutResID) {
        View view = View.inflate(this, layoutResID, null);
        setContentView(view);
    }*/

    /*@Override
    public void setContentView(View view) {
        super.setContentView(view);

        mContentView = view;

        initView();
        initData();
    }*/

//    protected abstract void initView();

    protected abstract void initData();

    public void hideLoadingDialog() {

        if (mProgressDialog != null) {
            mProgressDialog.hide();
        }

    }

    public void showLoadingDialog() {
        mProgressDialog = new MProgressDialog(this, true);
        mProgressDialog.show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        ActivityStackManager.getInstance().pop(this);

        if (mPresenter != null) {
            mPresenter.onDestory();
            mPresenter = null;
        }

        if(mUnbinder != Unbinder.EMPTY){
            mUnbinder.unbind();
            mUnbinder = null;
        }


    }


}
